package homework;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

/**
 * @author DCSGO
 * @version 1.0
 * (1)使用字符流的方式，编写一个客户端程序和服务器端程序
 * (2)客户端发送"name",服务器端接收到后，返回"我是 shroud"
 * (3)客户端发送"hobby"，服务器端接收到后，返回"编写java程序"
 */
public class Homework01Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket(InetAddress.getLocalHost(), 9999);
        //Socket socket = new Socket(InetAddress.getByName("47.113.198.9"), 9999);

        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        //bw.write("name");
        //bw.write("hobby");
        bw.write("你好！");

        bw.newLine();
        bw.flush();
        socket.shutdownOutput();
        System.out.println("已发送信息！");

        //接收服务端回复的消息
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        System.out.println("已收到服务端回复信息：" + br.readLine());

        br.close();
        bw.close();
        socket.close();

        /*
         * 已发送信息！
         * 已收到服务端回复信息：你说啥呢
         *
         * 进程已结束，退出代码为 0
         */
    }
}
